Kotlin also offers sealed classes. These are more restricted than regular classes, in that all subclasses of the sealed class must be declared in the same file as is the sealed class itself.

To mark a class as sealed, add the sealed keyword to its declaration.

Subclasses do not have to be nested, as they are here, though that was a requirement in early versions of Kotlin.

You can learn more about this in:
Run Edit